package de.metalcon.gwt.server.db.nodes;

import java.util.HashMap;

import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;

import de.metalcon.gwt.server.db.ANode;
import de.metalcon.gwt.server.db.Relations;

public class User extends ANode {
	static final char typePrefix = 'u';
	
	@SuppressWarnings({ "rawtypes", "serial" })
	private static final HashMap<String, Class> AllowedProperties = new HashMap<String, Class>() {
		{
			put("GlobalKey", String.class);
			put("FirstName", String.class);
			put("LastName", String.class);
		}
	};

	public User(Node node) {
		super(node);
	}

	public User(GraphDatabaseService db, String key) {
		super(db, key);
	}

	@Override
	public char getTypePrefix() {
		return typePrefix;
	}

	public static char GetTypePrefix() {
		return typePrefix;
	}

	public static User Create(GraphDatabaseService db, String[] keyProposals) {
		return new User(db, GenerateGlobalKey(db, keyProposals, GetTypePrefix()));
	}

	public static User Get(GraphDatabaseService db, String key) {
		return (User) ANode.Get(db, key, typePrefix);
	}

	public void addFriend(User friend) {
		addRelationshipTo(friend, Relations.FriendOf);
	}

	@SuppressWarnings("rawtypes")
	@Override
	protected HashMap<String, Class> getAllowedProperties() {
		return AllowedProperties;
	}
}
